<template>
  <div class="loginBox">
    <h2 class="title1">系统登录</h2>
    <div class="loginBoxForm">
      <el-input type="text" v-model="loginForm.userName" auto-complete="off" placeholder="账号"></el-input>
      <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
      <div class="btn">
        <span @click="login">登录</span>
      </div>
    </div>
   
  <div class="footer">
    <p>北京高拓电子科技有限责任公司  北京壹灵壹教育科技股份有限公司</p>
				<p>京公网安备 11010502038243号&nbsp;&nbsp;&nbsp;&nbsp;Copyright chinaedu.com, All Rights Reserved&nbsp;&nbsp;&nbsp;&nbsp;京ICP证010506号&nbsp;&nbsp;京ICP备11011674号-1</p>
  </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import Cookies from "js-cookie"
import ThemePicker from "@/components/ThemePicker"
import LangSelector from "@/components/LangSelector"
import { baseUrl } from "@/utils/global";
import axios from 'axios'
import Vue from 'vue'

export default {
  name: 'MobileLogin',
  components:{
    ThemePicker,
    LangSelector
  },
  data() {
    return {
     
      isLogin:false,
      loading: false,
      loginForm: {
        userName: '',
        password: '',
        verificationCode:'',
        src: ''
      },
      checked: true
    }
  },
  methods: {
    login() {
      this.loading = true
      let userInfo = {userName:this.loginForm.userName, password:this.loginForm.password}
      // axios.post(baseUrl+'/systemUser/login',userInfo,withCredentials).then(res=>{
      //   console.log(res)
      // })
      this.$api.login.login(userInfo).then((res) => {
          
          if(res.result===1) {
            console.log(res.data.user.userName)
            this.isLogin=true
            Cookies.set('webuser',res.data.user.userName);
            Cookies.set('token',res.data.token);
            localStorage.setItem('token',res.data.token)
            Cookies.set('realName',res.data.user.realName);
            Cookies.set('realName',res.data.user.realName);
            Cookies.set('userId',res.data.user.id);
            Cookies.set('threeLevelDeptId',res.data.user.threeLevelDeptId);
            Cookies.set('realName',res.data.user.realName);
            // this.$store.commit('menuRouteLoaded', false) // 要求重新加载导航菜单
            this.$router.push('/MobileIntro')  // 登录成功，跳转到主页
            // 获取客户来源等信息存储到本地
            this.getSchoolRecodType()
            this.getSchoolType()
            this.getSchoolSource()
            this.getSchoolDataFromType()
            this.getSchoolProgress()
            this.getLevleCache()
            this.getInvestmentType()
            this.getInvestmentDataFromType()
            this.getcommunication()
            this.getInvestmentSource()
            this.getInvestmentProgress()
          
            this.$message({
              message: res.msg,
              type: 'success'
            })
          } else {
            this.refreshCaptcha()
            this.$message({
              message: res.msg,
              type: 'error'
            })
          }
          this.loading = false
        }).catch((res) => {
          this.$message({
          message: res.message,
          type: 'error'
          })
        });
    },
    refreshCaptcha: function(){
      this.loginForm.src = this.global.baseUrl + "/validateCode?d="+Math.random();
    },
    aa:function(){
      this.refreshCaptcha()
    },
   
    _isMobile() {
      let flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      );
      // localStorage.setItem('isiphone',flag)
      localStorage.setItem("ismobile", flag ? 1 : 0);
      return flag;
    },
    
    // 获取学生客户客户类型
    getStudentType:function(){
      this.$api.user.optionsList({ codeType: "student_type" }).then(res => {
        localStorage.setItem("stdentTpye",JSON.stringify(res.keyValueList))
      });
    },
    // 学生客户获取方式
    getStudentDataFromTpye() {
      this.$api.user.optionsList({ codeType: "student_data_from_type" }).then(res => {
        localStorage.setItem('stdentDataFromType',JSON.stringify(res.keyValueList))
      });
    },
    // 学生客户客户来源
    getStudentSource(){
      this.$api.user.optionsList({ codeType: "student_data_from" }).then(res => {
        localStorage.setItem('studentSource',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学生客户进展
    getStudenProgress(){
      this.$api.user.optionsList({ codeType: "student_progress" }).then(res => {
        localStorage.setItem('studenProgress',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学校客户类型
    getSchoolType(){
      this.$api.user.optionsList({ codeType: "school_type" }).then(res => {
        localStorage.setItem('schoolType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学校客户来源
    getSchoolSource(){
      this.$api.user.optionsList({ codeType: "school_data_from" }).then(res => {
        localStorage.setItem('schoolSource',JSON.stringify(res.keyValueList))
      });
    },
    // 学校客户获取方式
    getSchoolDataFromType() {
      this.$api.user.optionsList({ codeType: "school_data_from_type" }).then(res => {
        localStorage.setItem('schoolDataFromType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学校客户进展
    getSchoolProgress(){
      this.$api.user.optionsList({ codeType: "school_progress" }).then(res => {
        localStorage.setItem('schoolProgress',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学段
    getLevleCache(){
      this.$api.user.optionsList({ codeType: "school_section" }).then(res => {
        localStorage.setItem('schoolSection',JSON.stringify(res.keyValueList))
      });
    },
    // 获取代理商客户类型
    getInvestmentType(){
      this.$api.agent.investment_customer_type().then(res => {
        localStorage.setItem('investmentType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取代理商获取方式
    getInvestmentDataFromType(){
      this.$api.user.optionsList({ codeType: "student_data_from_type" }).then(res => {
        localStorage.setItem('investmentDataFromType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取代理商客户来源
    getInvestmentSource(){
      this.$api.agent.investment_customer_from().then(res => {
        localStorage.setItem('investmentSource',JSON.stringify(res.keyValueList))
      });
    },
    // 获取代理商客户进展
    getInvestmentProgress(){
       this.$api.agent.investment_customer_progress().then(res => {
         localStorage.setItem('investmentProgress',JSON.stringify(res.keyValueList))
      });
    },
    // 获取沟通形式
    getcommunication(){
        this.$api.user.optionsList({ codeType: "investment_communication_type" }).then(res => {
          localStorage.setItem('investmentCommunicationType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学制
    getSystemCache(){
      this.$api.user.optionsList({ codeType: "system_cache" }).then(res => {
        localStorage.setItem('systemCache',JSON.stringify(res.systemList))
      });
    },
    // 获取沟通方式(代理商跟学校)
    getContractType(){
      this.$api.user.optionsList({ codeType: "school_communication_type" }).then(res => {
        localStorage.setItem('contractType',JSON.stringify(res.keyValueList))
      });
    },
    // 获取学生沟通方式
    getStudentContractType(){
      this.$api.user.optionsList({ codeType: "student_communication_type" }).then(res => {
          localStorage.setItem('studentContractType',JSON.stringify(res.keyValueList))
        });
    },
    // 获取设备 、页面地址、分主题、推广来源（网推的）
    getEquipment(){
      this.$api.user.optionsList({ codeType: "student_equipment" }).then(res => {
          localStorage.setItem('studentEquipment',JSON.stringify(res.keyValueList))
      });
      this.$api.user.optionsList({ codeType: "student_extension_source" }).then(res => {
          localStorage.setItem('studentTGsource',JSON.stringify(res.keyValueList))
      });
    },
    // 请求三级部门
    get_deptLevel3() {
      this.$api.dropdown.deptLevel3School().then(res => {
        localStorage.setItem('deptLevel3School',JSON.stringify(res.departmentInfoList))
      });
      this.$api.dropdown.deptLevel3Chinaedu().then(res => {
        localStorage.setItem('deptLevel3Chinaedu',JSON.stringify(res.departmentInfoList))
      });
      this.$api.dropdown.deptLevel3Student().then(res => {
        localStorage.setItem('deptLevel3Student',JSON.stringify(res.departmentInfoList))
      });
      this.$api.dropdown.deptLevel3Xuecoo().then(res => {
        localStorage.setItem('deptLevel3Xuecoo',JSON.stringify(res.departmentInfoList))
      });
      // 获取OEM卡类型
      this.$api.dropdown.oemType().then(res =>{
         localStorage.setItem('oemType',JSON.stringify(res.keyValueList))
      })
    },
  
    // 获取报告类型
    get_reportType(){
      this.$api.user.optionsList({ codeType: "student_report_type" }).then(res => {
          localStorage.setItem('studentReportType',JSON.stringify(res.keyValueList))
      });
    },
    //获取报告结果
    get_reportResult(){
      this.$api.user.optionsList({ codeType: "student_report_result" }).then(res => {
          localStorage.setItem('studentReportResult',JSON.stringify(res.keyValueList))
      });
    },
   
    // 获取年级
    get_grade(){
      this.$api.user.optionsList({ codeType: "grade_cache" }).then(res => {
        let gradeList=res.commonGradeList.sort((a,b)=>{return a.fOrder-b.fOrder})
        localStorage.setItem('gradeCache',JSON.stringify(gradeList))
      });
    },
     
    // 获取沟通结果
    get_result(){
      this.$api.student.studentProgressResult().then(res=>{
         localStorage.setItem('progressResult',JSON.stringify(res.keyValueList))
      })
    },
    // 获取跟进时候的客户进展
    get_track_progress(){
      this.$api.student.studentTrackProgress().then(res=>{
         localStorage.setItem('studenProgress2',JSON.stringify(res.keyValueList))
      })
    },
    // 获取跟进时候客户类型
     get_track_type(){
      this.$api.student.studentTrackType().then(res=>{
         localStorage.setItem('stdentTrackTpye',JSON.stringify(res.keyValueList))
      })
    },
    // 获取科目
    getSubject(){
      this.$api.student.studentSubject().then(res=>{
        localStorage.setItem('studentSubject',JSON.stringify(res.specialtyList))
      })
    },
    getSchoolRecodType(){
      this.$api.dropdown.schoolVisitType().then(res => {
        localStorage.setItem('schoolRecordType',JSON.stringify(res.keyValueList))
      });
    }

  },
  mounted() {
    this._isMobile()
    document.body.className='loginBox'
  }
}
</script>

<style lang="scss" scoped>

.footer{
    color: #333;
    text-align: center;
    font-size: 12px;
    font-family: arial;
    padding: 20px 0px 20px;
    line-height: 20px;
    p{
      a{
        color: #333;
      }
    }
}


.loginBox{
  background: url(./Mobile/images/bac.png);
  width: 10rem;
  background-size: contain;
  height: 6.45rem;
  margin: 0;
  padding-top: 2.3rem;
  .loginBoxForm{
    width:8.3rem;
    height:4.5rem;
    background:rgba(255,255,255,1);
    box-shadow:0px 4px 9px 2px rgba(0,74,178,0.19);
    border-radius:0.27rem;
    margin: 0 auto;
    margin-top: 0.3rem;
    padding: 1.35rem 0; 
    .el-input{
      width:7.21rem;
      height:1rem;
      border-radius:0.53rem;
      margin-bottom: 0.53rem;
    }
    .btn{
      span{
        display: block;
        margin: 0 auto;
        width:7.2rem;
        font-size:0.48rem;
        color: #fff;
        text-align: center;
        line-height: 1.2rem;
        height:1.2rem;
        background:linear-gradient(90deg,rgba(87,184,255,1) 0%,rgba(44,130,255,1) 100%);
        border-radius:0.59rem;
      }
    }
  }
  .title1{
    font-size:0.77rem;
    text-align: center;
    font-family:MicrosoftYaHei;
    color:rgba(255,255,255,1);
    margin: 0;
  }
}
</style>
<style lang="scss">
.loginBox{
  #app{
  margin-top: 0px !important;
  }
}
body{
  margin: 0;
}
</style>
